package com.mszlu.blog.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mszlu.blog.common.Result;
import com.mszlu.blog.entity.Tag;
import com.mszlu.blog.service.TagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/tags")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping("/hot")
    public Result hot(){

        Page<Tag> page = new Page<>(1,5);

        tagService.page(page);

        return Result.success(page.getRecords());
    }

    @GetMapping("/detail/{id}")
    public Result detail_id(@PathVariable long id) {

        LambdaQueryWrapper<Tag> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        lambdaQueryWrapper.eq(Tag::getId,id);

        Tag one = tagService.getOne(lambdaQueryWrapper);

        return Result.success(one);
    }


    @GetMapping("/detail")
    public Result detail() {

        List<Tag> list = tagService.list();

        return Result.success(list);
    }

    @GetMapping
    public Result tags() {

        List<Tag> list = tagService.list();

        return Result.success(list);
    }

}
